package jinyilw.common;

public class DebugTools
{
	public static boolean debug = true;

	private DebugTools()
	{
	}

	public static void traceCaller()
	{
		if (!debug)
			return;
		StackTraceElement[] stack = Thread.currentThread().getStackTrace();
		int l = stack.length;
		for (int i = l - 1; i >= 2; i--)
		{
			StackTraceElement s = stack[i];
			System.out.println("-->" + (l - i) + " " + s.getFileName() + ": "
					+ s.getMethodName());
		}
	}

	public static void traceCaller2()
	{
		if (!debug)
			return;
		StackTraceElement[] stack = Thread.currentThread().getStackTrace();
		for (int i = 0; i < stack.length; i++)
		{
			StackTraceElement s = stack[i];
			System.out.format(" ClassName:%d\t%s\n", i, s.getClassName());
			System.out.format("MethodName:%d\t%s\n", i, s.getMethodName());
			System.out.format("  FileName:%d\t%s\n", i, s.getFileName());
			// System.out.format("LineNumber:%d\t%s\n\n", i, s.getLineNumber());
		}
	}
}
